﻿#ifndef CLIENTTHREAD_H
#define CLIENTTHREAD_H

#include "client_class_def.h"
#include <QThread>
#include <QMutex>

class ClientThread : public QThread{
    Q_OBJECT
public:
    explicit ClientThread(ClientWindow *cw, std::string pubkey, std::string prikey, QObject *parent = nullptr);
    bool getIsConnected();

protected:
    void run(void) override;

private:
    std::string prikey_;
    std::string pubkey_;
    bool is_connected_with_server_;
    std::string server_ip_;
    unsigned short server_port_;
    unsigned short local_port_;
    bool should_keep_running_;
    ClientWindow *cw_;
    bool should_send_;
    std::string send_buf_;
    unsigned int sock_cache_;
    QMutex* mtx_;
    bool is_send_complete_;

private slots:
    void OnAppClose();

public slots:
    void OnSendMessage(const char* msg);
    void OnReconfigureNetwork(int local_port, const char* server_ip, int server_port, int local_id, int target_port);

signals:
    void SignalSendMessage(const char* msg);
    void SignalReconfigureNetwork(int local_port, const char* server_ip, int server_port, int local_id, int target_port);
};

#endif // CLIENTTHREAD_H
